import { ref,reactive } from "vue";
import { LoginParam } from "@/api/user/userModel"; 
import { ElForm } from "element-plus";

export default function useBaseLogin() {  

    // 表单绑定的数据
    const formData = reactive<LoginParam>({
        username: '',
        password: '',
        code: ''
    })

    // const ruleFormRef = ref<FormInstance>()

    // 表单验证规则
    const rules = reactive({
        username: [{
            required: true, 
            message: '请输入账号', 
            trigger: 'change' 
        }],
        password: [{
            required: true, 
            message: '请输入密码', 
            trigger: 'change' 
        }],
        code: [{
            required: true, 
            message: '请输入验证码', 
            trigger: 'change' 
        }]
    })

    // 表单的ref属性(不是很懂...)
    const loginFormRef = ref<InstanceType<typeof ElForm>>()  

    return {
        formData,
        rules,
        loginFormRef
    }
}